
<template>
    <div class="port-page">
        <!-- 顶部按钮 -->
        <router-link to="/home">
         	<el-button type="info" class="add btn" style='margin-left: 5px;' @click="cancelf" icon="el-icon-caret-left">返回</el-button>
        </router-link>
        <el-button type="info" class="btn" :loading="searchLoading" @click="search" icon="search">查询</el-button>
        <el-button type="success" class="btn" @click='componentsShow("add")' icon="edit">添加</el-button>

        <!-- 模糊搜索条件 -->
        <div class="search">

            <div class="search-item">
                <span>学生姓名：</span>
                <el-input placeholder="请输入学生姓名" class="code-search" v-model="studentName" icon="search" @keyup.enter.native="search"></el-input>
            </div>
<!--
            <div class="search-item">
                <span>电话：</span>
                <el-input placeholder="请输入电话" class="code-search" v-model="studentPhone" icon="search"></el-input>
            </div>

            <div class="search-item">
                <span>班级：</span>
                <el-input placeholder="请输入班级" class="code-search" v-model="studentClass" icon="search"></el-input>
            </div> -->

            <div class="search-item">
                <span>是否分配班级：</span>
                <el-switch v-model="isClass" on-text="是" off-text="否"></el-switch>
            </div>
            <!-- <el-button type="info" class="submit narrow">查询</el-button>   -->
        </div>

        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
            :v-loading="false"
            element-loading-text="拼命加载中"
            border
            align="center"
            class="admin-table"
            :row-class-name="tableRowClassName"
            @select="checkSelect"
            @select-all="checkall">

            <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>

            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference">
                        <img
                        :src="scope.row.xb == '男' ? $store.state.sexImg.boy : $store.state.sexImg.girl"
                        style="width:20px;vertical-align:middle;"
                        v-if="scope.column.property == 'zwm'">
                        <span style="vertical-align:middle;">{{ scope.row[scope.column.property] }}</span>
                    </div>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页查询区域 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>


        <!-- 各个组件显示区域 -->

        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>

        <!-- 新增组件 -->
        <AddComponent v-if="portComponents.add.toggle" @close="componentsHide"></AddComponent>

        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
    </div>
</template>

<script>
    import { mapState } from 'vuex'
    import LoadingComponent from 'components/loading'
    import AddComponent from './add'
    export default {
        components: { LoadingComponent, AddComponent },
        data () {
            return {
                isClass: true,
                studentName: '',
                studentPhone: '',
                studentClass: '',
                /*组件区域*/
                portComponents: {
                    add: {
                        type: 'add',
                        toggle: false,
                        params: '',
                        data: {}
                    }
                },

                multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据

                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                */
                portTitleList: [
                    {
                        prop:'id',
                        label:'id',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'zwm',
                        label:'姓名',
                        hide:1,
                        align:'left',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'left'
                    },{
                        prop:'xb',
                        label:'性别',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'csrq',
                        label:'出生日期',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'zsly',
                        label:'招生来源',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'dh',
                        label:'学生手机号',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'fmdh',
                        label:'父母手机号',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'wx',
                        label:'微信号',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'jtdz',
                        label:'家庭地址',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'glxx',
                        label:'公立学校',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'njbj',
                        label:'年级班级',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    },{
                        prop:'bj',
                        label:'班级',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'120',
                        headerAlign:'center'
                    }
                ],

                /*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画

                /*模糊搜索条件*/
                inputjkname:'' , //  接口名称,


                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
                pageindex: 1,//当前分页页码
                pagesizes: [12, 24, 36, 72],//显示个数的选择器选项
                pagesize: 12,//每页显示条目数
                total: 0,//总条数


                dropDownData:'', //
            }
        },
        created () {

            //加载页面时调用
            this.$store.dispatch('changeTitle','学生信息');//修改title
            this.$store.dispatch('changeRouterIndex','/cost/student-info');//修改路由

            this.search();//分页获取默认数据

            this.isLoading = true;//动画开始

        },
        mounted () {
            this.isLoading = false;//动画结束
        },
        methods: {
            tableRowClassName (row, index) {//隔行变色颜色设置
                /*if ( index%4 == 0) {
                    return "table-cell-green";
                }else if( index%4 == 1 ){
                    return "table-cell-yellow";
                }else if( index%4 == 2 ){
                    return "table-cell-red";
                }else{
                    return "table-cell-blue"
                }*/
            },
            tableCellControl (scope) {//表格单元格控制CSS样式
                /*if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
            },


            search () {//查询搜索触发事件
                this.searchLoading = true;
                var params3 = qs.stringify({
                  zwm:this.studentName,
                  // isfpbj:this.isClass ? "Y":"N",
                  pageindex: this.pageindex,
                  pagesize: this.pagesize
    						});
                this.axios.post(this.$store.state.api + 'xs/mc',params3)
                .then( res => {
                    console.log(res)

                    let data = res.data.data;
                    let list = data.list;
                    this.total = data.totalPage;
                    this.dataList = list;

                    this.searchLoading = false;
                }).catch( res => {
                    console.log(res)
                    this.searchLoading = false;
                })
            },



            handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },

            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                console.log(selection, row)
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                // console.log(selection)
                let strID = [];

                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                // console.log(strID.join(","))
                this.multipleDelNum = strID.join(",");
                // console.log(strID)
            },







            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                console.log(type,data)
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        console.log(this.portComponents[i])

                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;

                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id

                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;

                        }else{
                            return;
                        }
                        return;
                    }
                }

            },
            componentsHide (setting) { //关闭组件
                console.log(setting)
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;

                        if (!setting.cancel) {
                           this.search();
                        }
                        return;
                    }
                }
            }

        },
        computed: {
            multipleDeleteDisabled () {
                console.log(this.multipleDelNum)
                if (this.multipleDelNum) {
                    return false;
                }else{
                    return true
                }
            }
        }
    }
</script>

<style lang="less" scoped>
    .port-page {
        font-size:12px;

        .submit {
            width: 80px;
        }
        .code-search {
            width: 150px;
            height: 30px;
            margin:10px 0 10px 0;
        }

        .change-time{
            width: 480px;
            display: inline-block;
        }

        .class-page {
            text-align: left;
            margin-top:10px;
        }

        .search-item {
            display: inline-block;
            margin-right:10px;
        }

    }
</style>
